{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d473489d-583d-4e73-8d24-7fc4baabd25b",
   "metadata": {},
   "source": [
    "# 逻辑回归计算过程推导\n",
    "\n",
    "原文: https://blog.csdn.net/ligang_csdn/article/details/53838743\n",
    "\n",
    "## 一、 分类函数\n",
    "\n",
    "$g(z)=\\frac{1}{1+e^{-z}}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "9b7acac8-bc5f-4a31-b7f6-84b57030fd8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.36787944117144233\n",
      "sigmoid(1) =  0.7310585786300049\n",
      "1.0\n",
      "sigmoid(0) =  0.5\n",
      "2.718281828459045\n",
      "sigmoid(-1) =  0.2689414213699951\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "def sigmoid(x):\n",
    "    print(math.exp(-x))\n",
    "    return 1.0/(1+math.exp(-x))\n",
    "\n",
    "print('sigmoid(1) = ', sigmoid(1))\n",
    "print('sigmoid(0) = ', sigmoid(0))\n",
    "print('sigmoid(-1) = ', sigmoid(-1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8eabe13f-6ee4-4330-a861-cf3bc849f91c",
   "metadata": {},
   "source": [
    "## 二、 决策边界\n",
    "\n",
    "### 一)、 线性决策边界\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "beb43136-aeb5-4524-b0f3-6eb12226becd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAmQklEQVR4nO3deXQUdb7+8fcnIawhQS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AQiInFORSAiEudUBCIicU5FICIS51QEIiJx7v8DRgpwzrEnresAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "liner_example = [\n",
    "    [1, 0, 0],\n",
    "    [1, 1, 0],\n",
    "    [0, 1, 0],\n",
    "    [2, 0, 0],\n",
    "    [0, 2, 0],\n",
    "    [3, 2, 1],\n",
    "    [2, 3, 1],\n",
    "    [2, 2, 1],\n",
    "    [4, 0, 1],\n",
    "    [0, 4, 1],\n",
    "]\n",
    "\n",
    "fig = plt.figure()\n",
    "xcord1 = []\n",
    "ycord1 = []\n",
    "xcord2 = []\n",
    "ycord2 = []\n",
    "for n in range(len(liner_example)):\n",
    "    if liner_example[n][2] == 0:\n",
    "        xcord1.append(liner_example[n][0])\n",
    "        ycord1.append(liner_example[n][1])\n",
    "    else:\n",
    "        xcord2.append(liner_example[n][0])\n",
    "        ycord2.append(liner_example[n][1])\n",
    "plt.scatter(xcord1, ycord1,s=30, c='red', marker='s')\n",
    "plt.scatter(xcord2, ycord2, s=30, c='green')\n",
    "\n",
    "x1 = [0, 3]\n",
    "x2 = [3, 0]\n",
    "plt.xlabel('X1')\n",
    "plt.ylabel('X2')\n",
    "plt.plot(x1, x2)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6ad56b9-393e-4a77-963f-a51c13f301a2",
   "metadata": {},
   "source": [
    "### 二）、非线性决策边界"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1e71142-63bf-4f2c-8cfc-f77fba13c4a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_circle(center=(0,0), r=1):\n",
    "    x = np.linspace(center[0]-r, center[0]+r, 500)\n",
    "    y1 = np.sqrt(r**2 - x**2)\n",
    "    y2 = -y1\n",
    "    plt.plot(x, y1)\n",
    "    plt.plot(x, y2, c='C0')\n",
    "plt.xlim(-2, 2)\n",
    "plt.ylim(-2, 2)\n",
    "xcord1 = [-0.5, -0.5, 0, 0.5, 0.5]\n",
    "ycord1 = [-0.5, 0.5, 0, -0.5, 0.5]\n",
    "plt.scatter(xcord1, ycord1, s=30, c='red', marker='s')\n",
    "xcord2 = [-1.5, -1.5, -1.5, -1, -1, 1, 1, 1.5, 1.5, 1.5]\n",
    "ycord2 = [1, 0, -1, 1, -1, 1, -1, 1, 0, -1]\n",
    "plt.scatter(xcord2, ycord2, s=30, c='green')\n",
    "plot_circle()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d46fc73d-f1a3-4ce5-9666-207fb4667a52",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
